diff --git a/http.c b/http.c
index b04af9a..5183a11 100644
--- a/http.c
+++ b/http.c
@@ -3995,6 +3995,9 @@ evhttp_request_free(struct evhttp_request *req)
 		return;
 	}
 
+	if (req->on_free_cb)
+		(*req->on_free_cb)(req, req->on_free_cb_arg);
+
 	if (req->remote_host != NULL)
 		mm_free(req->remote_host);
 	if (req->uri != NULL)
@@ -4074,6 +4077,14 @@ evhttp_request_set_on_complete_cb(struct evhttp_request *req,
 	req->on_complete_cb_arg = cb_arg;
 }
 
+void
+evhttp_request_set_on_free_cb(struct evhttp_request *req,
+    void (*cb)(struct evhttp_request *, void *), void *cb_arg)
+{
+	req->on_free_cb = cb;
+	req->on_free_cb_arg = cb_arg;
+}
+
 /*
  * Allows for inspection of the request URI
  */
diff --git a/include/event2/http.h b/include/event2/http.h
index ed9acf4..3a73c6c 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -642,6 +642,20 @@ EVENT2_EXPORT_SYMBOL
 void evhttp_request_set_on_complete_cb(struct evhttp_request *req,
     void (*cb)(struct evhttp_request *, void *), void *cb_arg);
 
+/**
+ * Set a callback to be called on request free.
+ *
+ * The callback function will be called just before the evhttp_request object
+ * is destroyed.
+ *
+ * @param req a request object
+ * @param cb callback function that will be called before request free
+ * @param cb_arg an additional context argument for the callback
+ */
+EVENT2_EXPORT_SYMBOL
+void evhttp_request_set_on_free_cb(struct evhttp_request *req,
+    void (*cb)(struct evhttp_request *, void *), void *cb_arg);
+
 /** Frees the request object and removes associated events. */
 EVENT2_EXPORT_SYMBOL
 void evhttp_request_free(struct evhttp_request *req);
diff --git a/include/event2/http_struct.h b/include/event2/http_struct.h
index 4bf5b1f..0762cab 100644
--- a/include/event2/http_struct.h
+++ b/include/event2/http_struct.h
@@ -142,6 +142,12 @@ struct {
 	 */
 	void (*on_complete_cb)(struct evhttp_request *, void *);
 	void *on_complete_cb_arg;
+
+	/*
+	 * Free callback - called just before the request is freed.
+	 */
+	void (*on_free_cb)(struct evhttp_request *, void *);
+	void *on_free_cb_arg;
 };
 
 #ifdef __cplusplus
diff --git a/configure.ac b/configure.ac
index e5088ac..7810b49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -254,11 +254,6 @@ AC_CHECK_HEADERS([ \
   errno.h \
 ])
 
-AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-])
 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
 	AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
 	AC_EGREP_CPP(yes,
@@ -330,13 +325,6 @@ if test "x$ac_cv_header_sys_time_h" = "xyes"; then
 )
 fi
 
-if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
-	AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
-	   [[#include <sys/types.h>
-	     #include <sys/sysctl.h>]]
-	)
-fi
-
 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
 AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
 AM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue)
